This is the fifth in a series of lessons on the use of the QCard32.DLL.
Where to Find QCard32.DLL
This series of lessons uses the Qcard32.dll, a freeware library of playing card images. It is written by Stephen Murphy. Qcard32.DLL website: [http://www.telusplanet.net/public/stevem/] You can also obtain a copy of the DLL in issue #120 of the Liberty BASIC Newsletter.
What is in QCard32.DLL?
The DLL includes card face images for all suits and number values, from Ace to King, with hearts, spades, diamonds and clubs. There is a choice of six card backs. There are also jokers. It doesn't just provide images, though. It provides a way to manage the cards.
Getting Card Info
In earlier lessons, we discussed dealing the cards, showing their fronts or their backs, and changing the card back design. To create a playable game, we must ascertain the suit and value of a card selected by the user. In Lesson 4, we discovered the card that was clicked by the user and found its index in our card array. With that index, we can find out more about the card.
Suit?
Remember, we have filled an array called card() with a set of shuffled cards. When we know which card from the array was selected by the user, we check the value of that card and place it into a variable called clickCard . See Lesson 4 to refresh your memory on this.
There is a function in the Qcard DLL to get the suit of a card, called GetCardSuit() It requires the index number of the card, and returns the suit as a number. A return of 1 means the card is a club, 2 means it is a diamond, 3 means it is a heart and 4 means that it is a spade.
calldll #qc, "GetCardSuit",_ nIndex as long,_ 'index of card to query suit as long 'returns 1=Clubs, 2=Diamonds, 3=Hearts, 4=Spades.
Here is the API call, wrapped in a Liberty BASIC function:
Function GetCardSuit(nC)
'returns 1=Clubs, 2=Diamonds, 3=Hearts, 4=Spades.
calldll #qc, "GetCardSuit",nC as long,_
GetCardSuit as long
End Function
Value?
In a very similar way, we can get the value of the card. The function from the DLL is GetCardValue . The first argument is the index of the card to query. The function returns the value of the card, where an ace is 1, a deuce is 2, and so on, up to 11 for jack, 12 for queen, and 13 for king.
calldll #qc, "GetCardValue",_ nIndex as long,_ 'index of card to query value as long 'ace=1,deuce=2....jack=11,queen=12,king=13
Here is the API call, wrapped in a Liberty BASIC function:
Function GetCardValue(nC)
'ace=1,deuce=2....jack=11,queen=12,king=13
calldll #qc, "GetCardValue",nC as long,_
GetCardValue as long
End Function
Color?
We don't need to know the color of a card in our demo, but there is a function for this in the Qcard DLL. The first argument is the index of the card, and it returns the color. A return of 1 means the card is black, while 2 means that it is red.
calldll #qc, "GetCardColor",_ nIndex as long,_ 'index of card to query color as long '1=black, 2=red
Status?
In our demo, we've used the function SetCardStatus to cause either the back or the front of a card to be displayed. There is also a function to GetCardStatus in the DLL. The first argument is the index of the card to query, and the return is the card's status. A status of 1 means that the card is face up, while 0 means that it is face down.
calldll #qc, "GetCardStatus",_ nIndex as long,_ 'index of card to query status as long '1=face up, 0=face down
DEMO
The demo program that accompanies this lesson allows the user to click on one of the cards, and the program ascertains the suit and value of the card. It then gives the user a message stating which suit and value were chosen.

See the zipped archive for this newsletter to find cards5.bas and the WAV sounds that accompany the program. The DLL is available at [http://www.telusplanet.net/public/stevem/]